﻿Imports System.Windows.Forms

Public Class PreferencesDialog
    Dim downloads_fbd As FolderBrowserDialog

    Private Sub PreferencesDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Icon = My.Resources.icon
        Dim configfile As String = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\WSI\Config\User.xml"
        If ReadXML.Read(configfile, "UserConfig", "AutoUpdate") = "1" Then
            AutoUpdateCheckbox.Checked = True
        Else
            AutoUpdateCheckbox.Checked = False
        End If

        downloads_fbd = New FolderBrowserDialog
    End Sub
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SAVE_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub AutoUpdateCheckbox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AutoUpdateCheckbox.Click
        Dim configfile As String = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\WSI\Config\User.xml"
        If ReadXML.Read(configfile, "UserConfig", "AutoUpdate") = "1" Then
            ReadXML.Modify(configfile, "UserConfig", "AutoUpdate", "0")
        Else
            ReadXML.Modify(configfile, "UserConfig", "AutoUpdate", "1")
        End If
    End Sub


    Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
        downloads_fbd.Description = "Select where you want to place downloaded program installers."
        downloads_fbd.ShowDialog()

    End Sub

    Private Sub FolderBrowserDialog1_HelpRequest(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FolderBrowserDialog1.HelpRequest
        fbd_textbox.Text = downloads_fbd.SelectedPath
        ReadXML.Modify(Environment.SpecialFolder.LocalApplicationData & "\WSI\Config\User.xml", "UserConfig", "Downloads", downloads_fbd.SelectedPath)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If downloads_fbd.SelectedPath = "" Then
            If ReadXML.Read(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\WSI\Config\User.xml", "UserConfig", "Downloads") = "" Then
                downloads_fbd.SelectedPath = Environment.SpecialFolder.MyDocuments & "\WSI Downloads"
            Else
                downloads_fbd.SelectedPath = ReadXML.Read(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\WSI\Config\User.xml", "UserConfig", "Downloads")
            End If
        End If
        fbd_textbox.Text = downloads_fbd.SelectedPath

    End Sub
End Class
